<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
class PositionController extends AdminController {
	public function _initialize(){
		parent::_initialize();
	}
	//空操作
	public function _empty(){
		header("HTTP/1.0 404 Not Found");
		$this->display('Public:404');
	}
    /**
     * 轮播或banner显示的位置
     * @author      ZhangLiLi <379417738@qq.com>
     * @version	  v1.0.0 
     * @copyright  2016-12-22 下午1:13:44
     */
    public function index(){
      	$position = M('Position');
      	$where["status"]=array("NEQ","-1");
      	$count=$position->where($where)->count();
      	$Page   = new \Think\Page($count,10);
      	$show   = $Page->show();
      	$list=$position->where($where)->order('add_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
      	$this -> assign('position',$list);
      	$this->assign('page',$show);
      	$this -> display();
    }
    /**
     * 添加或修改显示
     * @author      ZhangLiLi <379417738@qq.com>
     * @version	  v1.0.0 
     * @copyright  2016-12-22 下午1:17:29
     */
    public function insert(){
    	$where['position_id']=I('position_id')?I('position_id'):null;
    	if(!empty($where['position_id'])){
    		$but="修改";
    		$list = M('Position') -> where($where) -> find();
    		$this -> assign('list',$list);
    	}else{
    		$but="添加";
    	}
    	$this->assign("but",$but);
    	$this->display();
    }
    /**
     * 添加或修改
     * @author      ZhangLiLi <379417738@qq.com>
     * @version	  v1.0.0 
     * @copyright  2016-12-22 下午1:17:47
     */
	public function add(){
		$data['name']=I("name","");
		$where["position_id"]=I("position_id","");
		if(!empty($where["position_id"])){
		 	//更改
	        $re=M('Position') -> where($where) ->save($data);
	        $su_str='修改成功';
	        $er_str='修改失败';
		}else{
			//添加
			$data['status']=I("status","1");
			$data['add_time']=time();
			if(empty($data['name'])){
	        	$this -> error('位置名称不能为空');
	        }
			$re=M('Position') ->add($data);
			$su_str='添加成功';
			$er_str='添加失败';
		}
		if($re){
      		$this -> success($su_str,U('Position/index'));
      	}else{
      		$this -> error($er_str);
      	}
	}
	/**
	 * 删除
	 * @author      ZhangLiLi <379417738@qq.com>
	 * @version	  v1.0.0 
	 * @copyright  2016-12-22 上午11:36:15
	 */
    public function delete(){
    	$position=M("Position");
     	$where['position_id'] = I('position_id')?I('position_id'):null;
      	if(!empty($where['position_id'])){
      		$res=$position->where($where)->setField('status','-1');
      		if($res){
      			$this->success('删除成功',U('Position/index'));
      		}else{
      			$this->error('删除失败');
      		}
      		
      	}
    }
// 	/**
// 	 * 状态
// 	 * @author      ZhangLiLi <379417738@qq.com>
// 	 * @version	  v1.0.0 
// 	 * @copyright  2016-12-22 下午1:08:51
// 	 */
// 	public function open(){
// 		$where['position_id']=I('position_id')?I('position_id'):null;
// 		$list=M('Position')->where($where)->find();
// 		if($list['status']==2){
// 			$list=M('Position')->where($where)->setField('status','1');
// 			$this->success('状态修改成功');
// 		}
// 		if($list['status']==1){
// 			$list=M('Position')->where($where)->setField('status','2');
// 			$this->success('状态修改成功');
// 		}
// 	}


}